<template>
  <div>
    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="$parent.open" width="780px" append-to-body >
      <div class="center_dialog">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="类别名称" prop="typeName">
              <el-input v-model="form.typeName" placeholder="请输入类别名称" />
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
      </el-form>
      </div>
      <div align="center" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="() => $parent.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { postequipmenttype, putequipmenttype } from '@/api/equipment/equipment.js'
// import Upload from '@/components/upload/index.vue'
export default {
  props:['title','rowObj'],
  components:{
    // Upload
  },
  data (){
    return {
      form:{
        "typeName": '', //类别名称
        "remark": '' //备注
      },
      rules:{
        typeName:{ required: true, message: '必填', trigger: 'blur' },
        remark:{ required: false, message: '必填', trigger: 'blur' },
      }
    }
  },
  created(){
    this.getlist()
  },
  methods:{
     getlist(){
      // let data = await getdatalist({dictType:'base_unit'});
      // let params = await gettypelist();
      // let supplierdata= await getsupplierlist();
      // this.dict=data.data
      // this.typedict=params.data
      // this.supplierdict=supplierdata.data
      if(this.title === '修改类别'){//修改进入
        this.form = {...this.rowObj}
      }
    },
    //提交
    submitForm(){
      this.$refs['form'].validate((valid) => {
          if (valid) {
            if(this.title === '修改类别'){//修改
              let params={
                ...this.form
              }
              putequipmenttype(params).then(res=>{
                if(res.code === 200){
                  this.$message.success(res.msg)
                  this.$parent.open=false
                  this.$parent.getList()//重新查询列表
                }
              })
            }else{//新增
              let params={
                ...this.form
              }
              postequipmenttype(params).then(res=>{
                if(res.code === 200){
                  this.$message.success(res.msg)
                  this.$parent.open=false
                  this.$parent.handleUpdate()
                }
              })
            }
          }
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.center_dialog{
  // text-align: center;
  width: 50%;
  margin: 0px auto;
}
</style>